*** This do-file has the programs that create the nice tables used through the paper (Escuelas al Centro).

*** 1) Produces means by treatment arm, differences with pair FE, and p-values
	capture prog drop my_ptest_p_vs_pp_vs_c
	program my_ptest_p_vs_pp_vs_c, eclass
	
	*clus(clus_var)
	syntax varlist [if] [in], by(varname) clus_id(varname) strat_id(varlist) [ * ] /// clus_id(clus_var)  

	marksample touse
	markout `touse' `by'
	tempname mu_1 mu_2 mu_3 dif1 dif2 dif3 se_1 se_2 se_3 des_1 des_2 des_3 d_p1 d_p2 d_p3
	
	capture drop TD*
	tab `by' , gen(TD)
	foreach var of local varlist {
	 reg `var'  TD1 TD2 TD3  `if', nocons vce(cluster `clus_id')
	 matrix A=e(b)
	 sum `var' if TD1==1 & e(sample)==1
	 mat `mu_1' = nullmat(`mu_1'), r(mean)
	 mat `se_1' = nullmat(`se_1'), r(sd)
	 sum `var' if TD2==1 & e(sample)==1
	 mat `mu_2' = nullmat(`mu_2'),r(mean)
	 mat `se_2' = nullmat(`se_2'), r(sd)
	 sum `var' if TD3==1 & e(sample)==1
	 mat `mu_3' = nullmat(`mu_3'),r(mean)
	 mat `se_3' = nullmat(`se_3'), r(sd)
	 
	 /* CONTROL v. PEC */
	 reghdfe `var'  TD1 TD2 TD3   `if',  vce(cluster `clus_id') absorb(i.`strat_id')
	 test (_b[TD1]- _b[TD2]== 0)
	 mat `d_p1'  = nullmat(`d_p1'),r(p)
	 lincom (TD1-TD2)
	 mat `dif1' = nullmat(`dif1'), r(estimate)
	 mat `des_1' = nullmat(`des_1'), r(se)
	 
	 /* PEC vs. PECPLUS*/
	 test (_b[TD3]-_b[TD2]==0) /* Pregunta si la diferencia de los coeficientes es igual a 0 */
	 mat `d_p2' = nullmat(`d_p2'), r(p) /* En esa matriz va a meter filas nuevas y va a guardar los standard errors*/
	 lincom (TD3-TD2)
	 mat `dif2' = nullmat(`dif2'), r(estimate)
	 mat `des_2' = nullmat(`des_2'), r(se)
	 
	 /* CONTROL VS. PECPLUS*/
	 test (_b[TD1]-_b[TD3]==0) /* Pregunta si la diferencia de los coeficientes es igual a 0 */
	 mat `d_p3' = nullmat(`d_p3'), r(p) /* En esa matriz va a meter filas nuevas y va a guardar los standard errors*/
	 lincom (TD3-TD1)
	 mat `dif3' = nullmat(`dif3'), r(estimate)
	 mat `des_3' = nullmat(`des_3'), r(se)
	 
	 	}
	foreach mat in mu_1 mu_2 mu_3 dif1 dif2 dif3 se_1 se_2 se_3 des_1 des_2 des_3 d_p1 d_p2 d_p3{
	 mat coln ``mat'' = `varlist'
	}
	 local cmd "my_ptest_p_vs_pp_vs_c"
	foreach mat in mu_1 mu_2 mu_3 dif1 dif2 dif3 se_1 se_2 se_3 des_1 des_2 des_3 d_p1 d_p2 d_p3 {
	 eret mat `mat' = ``mat''
	}
	end
	
	
	
	*** 2) Produces means by treatment arm, differences with pair FE, and p-values, only for PEC and PEC+
	capture prog drop my_ptest_pec_vs_pecplus
	program my_ptest_pec_vs_pecplus, eclass
	
	*clus(clus_var)
	syntax varlist [if] [in], by(varname) clus_id(varname) strat_id(varlist) [ * ] /// clus_id(clus_var)  

	marksample touse
	markout `touse' `by'
	tempname mu_2 mu_3  dif2   se_2 se_3 des_2   d_p2 
	
	capture drop TD*
	tab `by' , gen(TD)
	foreach var of local varlist {
	 reghdfe `var'   TD2 TD1  `if', vce(cluster `clus_id') abs(`strat_id')
	 matrix A=e(b)

	 sum `var' if TD1==1 & e(sample)==1
	 mat `mu_2' = nullmat(`mu_2'),r(mean)
	 mat `se_2' = nullmat(`se_2'), r(sd)
	 sum `var' if TD2==1 & e(sample)==1
	 mat `mu_3' = nullmat(`mu_3'),r(mean)
	 mat `se_3' = nullmat(`se_3'), r(sd)
	 
	 
	 
	 /* PEC vs. PECPLUS*/
	 test (_b[TD2]-_b[TD1]==0) /* Pregunta si la diferencia de los coeficientes es igual a 0 */
	 mat `d_p2' = nullmat(`d_p2'), r(p) /* En esa matriz va a meter filas nuevas y va a guardar los standard errors*/
	 lincom (TD2-TD1)
	 mat `dif2' = nullmat(`dif2'), r(estimate)
	 mat `des_2' = nullmat(`des_2'), r(se)
	 
	 
	 	}
	foreach mat in mu_2 mu_3  dif2   se_2 se_3 des_2   d_p2{
	 mat coln ``mat'' = `varlist'
	}
	 local cmd "my_ptest_pec_vs_pecplus"
	foreach mat in mu_2 mu_3  dif2   se_2 se_3 des_2   d_p2 {
	 eret mat `mat' = ``mat''
	}
	end
	
	
*** 3) Produces means by treatment arm, differences with pair FE, and p-values. PEC+ vs Control
	capture prog drop my_ptest_ppecplus_vs_control
	program my_ptest_ppecplus_vs_control, eclass
	
	*clus(clus_var)
	syntax varlist [if] [in], by(varname) clus_id(varname) strat_id(varlist) [ * ] /// clus_id(clus_var)  

	marksample touse
	markout `touse' `by'
	tempname mu_1 mu_3   dif3 se_1  se_3   des_3 d_p3
	
	capture drop TD*
	tab `by' , gen(TD)
	foreach var of local varlist {
	 reghdfe `var'  TD1 TD2 TD3  `if', vce(cluster `clus_id')  abs(`strat_id')
	 matrix A=e(b)
	 sum `var' if TD1==1 & e(sample)==1
	 mat `mu_1' = nullmat(`mu_1'), r(mean)
	 mat `se_1' = nullmat(`se_1'), r(sd)

	 sum `var' if TD3==1 & e(sample)==1
	 mat `mu_3' = nullmat(`mu_3'),r(mean)
	 mat `se_3' = nullmat(`se_3'), r(sd)
	 
	 
	 /* CONTROL VS. PECPLUS*/
	 test (_b[TD1]-_b[TD3]==0) /* Pregunta si la diferencia de los coeficientes es igual a 0 */
	 mat `d_p3' = nullmat(`d_p3'), r(p) /* En esa matriz va a meter filas nuevas y va a guardar los standard errors*/
	 lincom (TD3-TD1)
	 mat `dif3' = nullmat(`dif3'), r(estimate)
	 mat `des_3' = nullmat(`des_3'), r(se)
	 
	 	}
	foreach mat in mu_1 mu_3   dif3 se_1  se_3   des_3 d_p3{
	 mat coln ``mat'' = `varlist'
	}
	 local cmd "my_ptest_ppecplus_vs_control"
	foreach mat in mu_1 mu_3   dif3 se_1  se_3   des_3 d_p3 {
	 eret mat `mat' = ``mat''
	}
	end
	
	*** 4) Produces means by treatment arm, differences with pair FE, and p-values. Treatment vs. No Treatment
	capture prog drop my_ptest_treat_vs_notreat
	program my_ptest_treat_vs_notreat, eclass
	
	*clus(clus_var)
	syntax varlist [if] [in], by(varname) clus_id(varname) [ * ] /// clus_id(clus_var)  

	marksample touse
	markout `touse' `by'
	tempname mu_t mu_nt   dift se_t  se_nt   des_t d_pt
	
	capture drop TD*
	tab `by' , gen(TD)
	foreach var of local varlist {
	 reg `var'  TD1 TD2 `if', nocons vce(cluster `clus_id')
	 matrix A=e(b)
	 sum `var' if TD1==1 & e(sample)==1
	 mat `mu_nt' = nullmat(`mu_nt'), r(mean)
	 mat `se_nt' = nullmat(`se_nt'), r(sd)

	 sum `var' if TD2==1 & e(sample)==1
	 mat `mu_t' = nullmat(`mu_t'),r(mean)
	 mat `se_t' = nullmat(`se_t'), r(sd)
	 
	 
	 /* CONTROL VS. PECPLUS*/
	 test (_b[TD2]-_b[TD1]==0) /* Pregunta si la diferencia de los coeficientes es igual a 0 */
	 mat `d_pt' = nullmat(`d_pt'), r(p) /* En esa matriz va a meter filas nuevas y va a guardar los standard errors*/
	 lincom (TD2-TD1)
	 mat `dift' = nullmat(`dift'), r(estimate)
	 mat `des_t' = nullmat(`des_t'), r(se)
	 
	 	}
	foreach mat in mu_t mu_nt   dift se_t  se_nt   des_t d_pt{
	 mat coln ``mat'' = `varlist'
	}
	 local cmd "my_ptest_treat_vs_notreat"
	foreach mat in mu_t mu_nt   dift se_t  se_nt   des_t d_pt {
	 eret mat `mat' = ``mat''
	}
	end
	
	
	*** 4) Produces means by treatment arm, differences with pair FE, and p-values. Treatment vs. No Treatment
	capture prog drop my_ptest_treat_vs_notreat_strata
	program my_ptest_treat_vs_notreat_strata, eclass
	
	*clus(clus_var)
	syntax varlist [if] [in], by(varname) clus_id(varname) strat_id(varlist)  [ * ] /// clus_id(clus_var)  

	marksample touse
	markout `touse' `by'
	tempname mu_t mu_nt   dift se_t  se_nt   des_t d_pt
	
	capture drop TD*
	tab `by' , gen(TD)
	foreach var of local varlist {
	 reghdfe `var'  TD1 TD2 `if', vce(cluster `clus_id') abs(`strat_id')
	 matrix A=e(b)
	 sum `var' if TD1==1 & e(sample)==1
	 mat `mu_nt' = nullmat(`mu_nt'), r(mean)
	 mat `se_nt' = nullmat(`se_nt'), r(sd)

	 sum `var' if TD2==1 & e(sample)==1
	 mat `mu_t' = nullmat(`mu_t'),r(mean)
	 mat `se_t' = nullmat(`se_t'), r(sd)
	 
	 
	 /* CONTROL VS. PECPLUS*/
	 test (_b[TD2]-_b[TD1]==0) /* Pregunta si la diferencia de los coeficientes es igual a 0 */
	 mat `d_pt' = nullmat(`d_pt'), r(p) /* En esa matriz va a meter filas nuevas y va a guardar los standard errors*/
	 lincom (TD2-TD1)
	 mat `dift' = nullmat(`dift'), r(estimate)
	 mat `des_t' = nullmat(`des_t'), r(se)
	 
	 	}
	foreach mat in mu_t mu_nt   dift se_t  se_nt   des_t d_pt{
	 mat coln ``mat'' = `varlist'
	}
	 local cmd "my_ptest_treat_vs_notreat_strata"
	foreach mat in mu_t mu_nt   dift se_t  se_nt   des_t d_pt {
	 eret mat `mat' = ``mat''
	}
	end
	
	
